package com.ly.cloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import com.ly.cloud.common.mybatisplus.plugins.PageInfo;
import com.ly.cloud.dto.DeleteFamilyDto;
import com.ly.cloud.dto.StuFamilyInfoDto;
import com.ly.cloud.dto.StudentInfoDto;
import com.ly.cloud.service.StuFamilyInfoService;
import com.ly.cloud.vo.StuFamilyInfoVo;
import com.ly.cloud.vo.StudentInfoVo;
import com.ly.cloud.web.utils.WebResponse;

/**
 * Description:该控制器用来用来操作学生家庭成员基本信息
 * @author luhuacong
 * @date: 2018年12月21日
 */
@RestController
@RequestMapping("/stuFamily")
public class StuFamilyInfoController {

	@Autowired
	private StuFamilyInfoService stuFamilyInfoService;
	
	/**(non-Javadoc)
	 * Title: insertStudentInfo
	 * Description: 
	 * 添加学生家庭成员信息
	 * @param dto 条件封装对象
	 * @param loginUserName 登录者
	 * @return  boolean
	 * @date: 2018年12月22日
	 * @author luhuacong
	 */
	@RequestMapping(value = "/insertStuFamilyInfo", method = RequestMethod.POST)
	public WebResponse<Boolean> insertStuFamilyInfo(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody StuFamilyInfoDto dto){
		boolean isSuccess = stuFamilyInfoService.insertStuFamilyInfo(dto, loginUserName);
		return new WebResponse<Boolean>().success(isSuccess);
	}
	
	/**(non-Javadoc)
	 * Title: deleteById
	 * Description: 
	 * 根据主键删除成员信息
	 * @param cyzj 成员主键
	 * @return  boolean
	 * @date: 2018年12月22日
	 * @author luhuacong
	 */
	@RequestMapping(value = "/deleteFamInfoByid/{cyzj}", method = RequestMethod.POST)
	public WebResponse<Boolean> deleteFamInfoByid(@PathVariable("cyzj") Long cyzj){
		boolean isSuccess = stuFamilyInfoService.deleteById(cyzj);
		return new WebResponse<Boolean>().success(isSuccess);
	}

	/** 
	 * Method Name:deleteFamliyList
	 * Description:批量删除家庭成员信息
	 * @param dto 条件封装对象
	 * @return 成功删除的个数
	 * @author LuHuaCong
	 * @date: 2018年12月22日
	 */
	@RequestMapping(value = "/deleteFamliyList", method = RequestMethod.POST)
	public WebResponse<Integer> deleteFamliyList(@RequestBody List<Long> idList){
		Integer count = stuFamilyInfoService.deleteFamliyList(idList);
		return new WebResponse<Integer>().success(count);
	}
	
	/**(non-Javadoc)
	 * Title: updateStuFamilyInfo
	 * Description: 
	 * 修改学生家庭成员信息
	 * @param dto 条件封装对象
	 * @param loginUserName 修改人
	 * @return  boolean
	 * @date: 2018年12月22日
	 * @author luhuacong
	 */
	@RequestMapping(value = "/updateStuFamilyInfo", method = RequestMethod.POST)
	public WebResponse<Boolean> updateStuFamilyInfo(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody StuFamilyInfoDto dto){
		boolean isSuccess = stuFamilyInfoService.updateStuFamilyInfo(dto, loginUserName);
		return new WebResponse<Boolean>().success(isSuccess);
	}
	
	/**(non-Javadoc)
	 * Title: selectFamListByxsid
	 * Description: 
	 * 根据学生id查询家庭成员信息
	 * @param xsid 学生id
	 * @param paheNum 当前页
	 * @param pageSize 每页显示条数
	 * @return  PageInfo<StuFamilyInfoVo>
	 * @date: 2018年12月22日
	 * @author luhuacong
	 */
	@RequestMapping(value = "/selectFamListByxsid", method = RequestMethod.GET)
	public WebResponse<PageInfo<StuFamilyInfoVo>> selectFamListByxsid(@RequestParam int pageNum, @RequestParam int pageSize,@RequestParam String xsid){
		Page<StuFamilyInfoVo> page = stuFamilyInfoService.selectFamListByxsid(new Page<StuFamilyInfoVo>(pageNum, pageSize),xsid);
		return new WebResponse<PageInfo<StuFamilyInfoVo>>().success(PageInfo.toPageInfo(page));
	}
}
